<template>
  <el-dialog :visible.sync="dialogVisible" width="800px" :before-close="handleClose" :close-on-click-modal="false"
    append-to-body :title="title">
    <el-form :model="form" ref="formRef" label-width="90px">
      <el-form-item label="医护人员" class="settle-dialog" prop="doctor_id" :rules="[
          { required: true, message: '请选择医护人员', trigger: 'blur' },
        ]">
        <el-select popper-class="popper-select" :popper-append-to-body="false" @change="$forceUpdate()"
          v-model="form.doctor_id" clearable filterable placeholder="请选择">
          <el-option v-for="item in doctorArr" :key="item.id" :label="item.name+'('+item.phone+')'" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="tx-c">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="confirm" :loading="btnLoading">通过</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { debounce } from "@/util";
import { ApiOrderAllocation, ApigetDoctorList } from "@/api/index.js";
import ImgUploadPath from "@/components/imgUpload-path.vue";
import { validatePhone } from "@/util/validate";
export default {
  props: ["roleData", "departmentData"],
  components: {
    ImgUploadPath,
  },
  data() {
    return {
      oldform: {
        doctor_id: null,
        /*    unit: "京山市人民医院", */
      },
      form: {},
      btnLoading: false,
      dialogVisible: false,
      id: null,
      item_id: null,
      title: "",
      doctorArr: [],
    };
  },

  methods: {
    confirm: debounce(
      function (val) {
        this.$refs["formRef"].validate(async (valid) => {
          if (valid) {
            this.btnLoading = true;
            try {
              await ApiOrderAllocation({
                ...this.form,
                order_id: this.id,
              });
              this.$message.success("修改成功");
              this.handleClose();
              this.$emit("refresh");
            } finally {
              this.btnLoading = false;
            }
          } else return false;
        });
      },
      500,
      true
    ),

    show(row) {
      if (row) {
        console.log(row)
        if (row.doctor_id) {
          this.$nextTick(() => {
            this.form.doctor_id = row.doctor_id
          })
        }
        this.id = row.id;
        this.item_id = row.item_id;
      }
      this.getDoctirList();
      this.dialogVisible = true;
    },
    getDoctirList() {
      ApigetDoctorList({ page: "1", size: "999", item_id: this.item_id }).then(
        (res) => [(this.doctorArr = res.data)]
      );
    },

    handleClose() {
      this.dialogVisible = false;
      this.form = { ...this.oldform };
      /*   this.$nextTick((_) => {
        this.$refs.formRef.clearValidate();
        this.$refs.ImgUploadPath.clear();
      }); */
    },
  },
};
</script>

<style scoped >
.settle-dialog ::v-deep .el-select-dropdown {
  position: absolute !important;
}
::v-deep .popper-select {
  position: absolute !important;
  top: 35px !important;
  left: 0px !important;
}
</style>
